using ASP;
using HoWave.Web;
using HoWave.Web.DataHelper;
using HoWave.Web.Shop;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Witkey_ListWitkey : Shop, IRequiresSessionState
{
	protected HiddenField HiddenField_Type;
	protected Button Button_xs;
	protected Button Button_zb;
	protected HtmlGenericControl spanType;
	protected LinkButton LinkButton1;
	protected LinkButton LinkButton2;
	protected LinkButton LinkButton3;
	protected LinkButton LinkButton4;
	protected LinkButton LinkButton5;
	protected Repeater Repeater_WitkeyXS;
	protected Repeater Repeater_WitkeyZB;
	protected Repeater Repeater_TypeOne;
	protected HtmlForm form1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Init(object sender, EventArgs e)
	{
		try
		{
			Template.BindTemplateToPage(this.Page, "SaleProduct");
		}
		catch (Exception ex)
		{
			base.WriteTemErrMsg(ex.Message.ToString());
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.Initpage();
			this.spanType.InnerHtml = "&nbsp;悬赏任务";
			this.HiddenField_Type.Value = "1";
		}
		this.WitkeyTypeBind();
	}
	protected void Initpage()
	{
		this.WitkeyXSBind(0, "");
		this.UpdateEnd();
	}
	protected void UpdateEnd()
	{
		Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
		DataTable witkeyAll = shop_Witkey.GetWitkeyAll();
		DateTime now = DateTime.Now;
		foreach (DataRow dataRow in witkeyAll.Rows)
		{
			DateTime t = Convert.ToDateTime(dataRow["ww_EndTime"]);
			if (now >= t)
			{
				string a = dataRow["ww_Statu"].ToString();
				if (a != "8" && a != "9" && a != "7" && a != "5" && a != "6" && a != "5" && a != "1")
				{
					shop_Witkey.UpdateWitkeyStatu(Convert.ToInt32(dataRow["ww_Id"]), 7);
					int userID = Convert.ToInt32(dataRow["ww_Uid"]);
					UserBll userBll = new UserBll(this.conn);
					DataTable userByUserID = userBll.GetUserByUserID(userID);
					userBll.UpdateUserScope(userID, Convert.ToDecimal(userByUserID.Rows[0]["Balance"]) + Convert.ToDecimal(dataRow["ww_xsPrice"]), Convert.ToInt32(userByUserID.Rows[0]["UserEP"]));
				}
			}
		}
	}
	protected void WitkeyTypeBind()
	{
		Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
		this.Repeater_TypeOne.DataSource = shop_Witkey.GetWitkeyTypeOneAll();
		this.Repeater_TypeOne.DataBind();
	}
	protected void WitkeyXSBind(int statu, string TypeTwo)
	{
		Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
		this.Repeater_WitkeyXS.DataSource = shop_Witkey.GetWitkeyAllByType(base.user.UserID, 1, 1, "", TypeTwo, statu, "");
		this.Repeater_WitkeyXS.DataBind();
	}
	protected void WitkeyZBBind(int statu, string TypeTwo)
	{
		Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
		this.Repeater_WitkeyZB.DataSource = shop_Witkey.GetWitkeyAllByType(base.user.UserID, 2, 1, "", TypeTwo, statu, "");
		this.Repeater_WitkeyZB.DataBind();
	}
	protected void Button_xs_Click(object sender, EventArgs e)
	{
		this.Repeater_WitkeyXS.Visible = true;
		this.Repeater_WitkeyZB.Visible = false;
		this.WitkeyXSBind(0, "");
		this.spanType.InnerHtml = "&nbsp;悬赏任务";
		this.HiddenField_Type.Value = "1";
	}
	protected void Button_zb_Click(object sender, EventArgs e)
	{
		this.Repeater_WitkeyXS.Visible = false;
		this.Repeater_WitkeyZB.Visible = true;
		this.WitkeyZBBind(0, "");
		this.spanType.InnerHtml = "&nbsp;招标任务";
		this.HiddenField_Type.Value = "2";
	}
	protected void LinkButton_Command(object sender, CommandEventArgs e)
	{
		int statu = Convert.ToInt32(e.CommandArgument);
		if (this.HiddenField_Type.Value == "1")
		{
			this.WitkeyXSBind(statu, "");
			this.spanType.InnerHtml = "&nbsp;悬赏任务";
			this.Repeater_WitkeyXS.Visible = true;
			this.Repeater_WitkeyZB.Visible = false;
		}
		else
		{
			this.WitkeyZBBind(statu, "");
			this.spanType.InnerHtml = "&nbsp;招标任务";
			this.Repeater_WitkeyXS.Visible = false;
			this.Repeater_WitkeyZB.Visible = true;
		}
	}
	protected void LinkButton_TypeName_Command(object sender, CommandEventArgs e)
	{
		string commandName = e.CommandName;
		if (this.HiddenField_Type.Value == "1")
		{
			this.WitkeyXSBind(0, commandName);
			this.spanType.InnerHtml = "&nbsp;悬赏任务";
			this.Repeater_WitkeyXS.Visible = true;
			this.Repeater_WitkeyZB.Visible = false;
		}
		else
		{
			this.WitkeyZBBind(0, commandName);
			this.spanType.InnerHtml = "&nbsp;招标任务";
			this.Repeater_WitkeyXS.Visible = false;
			this.Repeater_WitkeyZB.Visible = true;
		}
	}
	protected void Repeater_TypeOne_ItemDataBound(object sender, RepeaterItemEventArgs e)
	{
		Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
		Repeater repeater = (Repeater)e.Item.FindControl("Repeater_TypeTwo");
		HiddenField hiddenField = (HiddenField)e.Item.FindControl("HiddenField_TypeFID");
		repeater.DataSource = shop_Witkey.GetWitkeyTypeByTypeFId(int.Parse(hiddenField.Value));
		repeater.DataBind();
	}
}
